Computer programs are generally written in a high-level programming language such as Java or C++, which is edited and stored as text-based source code. Compilers are then used to translate the source code instructions of the high-level programming language into machine instructions that can be executed by a computer. The compilation process is generally divided into six phases:
1. Lexical analysis
2. Syntactic analysis
3. Semantic analysis
4. Intermediate code generation
5. Code optimization
6. Final code generation
During lexical analysis, the source code of the computer program is scanned and components or tokens of the high-level language are identified. The compiler then converts the source code into a series of tokens that can be processed during syntactic analysis. For example, during lexical analysis, the compiler would identify the statement,
cTable=1.0;
as tokens including the variable (cTable), the assignment operator (=), the constant (1.0), and a semicolon. A variable, operator, constant, and semicolon are tokens of the high-level language.
During syntactic analysis (also referred to as “parsing”), the compiler processes the tokens and generates a syntax tree to represent the program based on the syntax (also referred to as “grammar”) of the programming language. A syntax tree is a tree structure in which operators are represented by non-leaf nodes and their operands are represented by child nodes. In the above example, the assignment operator (=) has two operands: the variable (cTable) and the constant (1.0). The terms “parse tree” and “syntax tree” are used interchangeably in this description to refer to the syntax-based tree generated as a result of syntactic analysis. For example, such a tree optionally may describe the derivation of the syntactic structure of the computer program (e.g., it may describe that a certain token is an identifier, which is an expression as defined by the syntax). Syntax-based trees may also be referred to as “concrete syntax trees” when the derivation of the syntactic structure is included, and as “abstract syntax trees” when the derivation is not included.
During semantic analysis, the compiler modifies the syntax tree to ensure semantic correctness. For example, if the variable (cTable) is an integer and the constant (1.0) is a floating-point, then during semantic analysis a floating point to integer conversion would be added to the syntax tree.
During intermediate code generation, code optimization, and final code generation, the compiler generates machine instructions to implement the program represented by the syntax tree. A computer can then execute the machine instructions.
A system has been described for generating and maintaining a computer program represented as an intentional program tree, which is a type of syntax tree. (For example, U.S. Pat. No. 5,790,863 entitled “Method and System for Generating and Displaying a Computer Program” and U.S. Pat. No. 6,097,888 entitled “Method and System for Reducing an Intentional Program Tree Represented by High-Level Computational Constructs,” and U.S. Pat. No. 7,607,099 entitled “Method and system for reversible design tree transformations,” each of which is hereby incorporated by reference in its entirety for all purposes.) The system provides a mechanism for directly manipulating nodes corresponding to “program elements” by adding, deleting, and moving the nodes within an intentional program tree. An intentional program tree is one type of “program tree.” A “program tree” is a tree representation of a computer program that includes operator nodes and operand nodes representing program elements. A program tree may also include inter-node references (i.e., graph structures linking nodes in the tree), such as a reference from a declaration node of an identifier to the node that defines that identifier's type. For example, a node representing the declaration of an identifier to be an integer includes a reference (i.e., non-tree pointer) to a node that defines the integer type. An abstract syntax tree and a concrete syntax tree are examples of a program tree. Once a program tree is generated, the system performs the steps of semantic analysis, intermediate code generation, code optimization, and final code generation to transform the computer program represented by the program tree into executable code.
Various techniques have been used to control the editing of computer program. These techniques include text-based editors and structured editors. A programmer uses a text-based editor to enter the letters, numbers, and other characters that make up the source code for the computer program. The text-based editor may store these characters in an unstructured format in a source code file using an ASCII format and delimiting each line by an end-of-line character. The format is unstructured because computer program in that format needs to be parsed to identify the syntactic elements.
Modern integrated development environments (IDEs), such as Microsoft Visual Studio, Apple Xcode, Eclipse, Oracle Netbeans, and IntelliJ support interactive lexical and syntactic analysis of text-based source code as it is edited by the programmer via the IDE's editor. The IDEs typically maintain a structured representation of the source code based on the hierarchy of the programming language syntax. If the editor detects a lexical or syntactic error, it typically notifies the programmer via some indicia in the editor, such as marking the detected error in the portion of code for which the error is detected. Each of these IDEs store the source code in text format (e.g., as .h and .cpp files for C++, .Java files for Java, etc.), and typically rebuild the structured representation upon launching editing of an existing project. Notably, the text-based source code is not designed to be generated from the structured representation alone.
Each of the foregoing IDEs also support some form of source control, either via built-in functionality or integrated with a third-party source code repository, such as Subversion. Source control enables different versions of an application to be saved and restored, and includes information relating to identities of programmers who modify the source code, which portion of the source code has been modified for a given revision, and revision time-stamp information. All of this information is stored separate from the text-based source code and the structured representation under conventional implementations. IDEs may also provide editing tools that employ other types of structure representations, such as Xcode's Interface Builder (IB), which is used in connection with developing iOS applications. IB enables programmers to graphically design user interfaces, as well as visually link code to support various user interface functionality. IB generates an XML-based output file (XIB), which is used by Xcode to build the iOS application.